{% extends "base.html" %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<h1>{{ title }}</h1>


 <table>
    {% if user.is_authenticated %}
	<tr>
		<td></td>
		<td colspan="2"><input type="button" onclick="location='/create_recipe'" value="Create Recipe" id="create"></td>
	</tr>
	{% endif%}
{% if recipes %}
   
	
    
    {% for recipe in recipes %}
        <tr>
        	<td><a href="/recipe/{{ recipe.id }}/">{{ recipe.title }}</a></td>
        	{% if user.is_authenticated and user = recipe.user %}
        	<td>	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="location='/edit_recipe/{{ recipe.id }}/'" value="Edit"> </td><td><input type="button" onclick="window.delete({{recipe.id}})" value="Delete" /></td>
    
			
        
        	
        	{% endif %}
        </tr>
    {% endfor %}
    <script type="text/javascript">
    	
    	function delete(id){
    		 if(confirm('Are you sure you want to delete this recipe?')){
    		 	window.location = "/delete_recipe/"+id+"/";
    		 }
    		
    	}
    	
    </script>

{% else %}
   <tr> <td>No recipes are available.</td></tr>
{% endif %}
 </table>
{% endblock %}